package com.link510.aitools.activity.airobot.led;

import android.os.Bundle;
import android.widget.EditText;

import com.blankj.utilcode.util.ToastUtils;
import com.google.common.base.Strings;
import com.link510.aitools.R;
import com.link510.aitools.core.listen.CWMListener;
import com.link510.aitools.core.message.MessageInfo;
import com.link510.aitools.framework.activity.BaseAcitivity;
import com.link510.aitools.services.Airobots;
import com.link510.aitools.services.CustomWaitDialogUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class RobotLedEditTextActivity extends BaseAcitivity {

    CustomWaitDialogUtils customWaitDialogUtils;

    @BindView(R.id.led_text)
    EditText ledTextEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_robot_led_edit_text);
        customWaitDialogUtils = new CustomWaitDialogUtils(RobotLedEditTextActivity.this);
    }

    @OnClick(R.id.send_button)
    public void sendButtonClick() {

        String text = ledTextEditText.getText().toString().trim();

        if (Strings.isNullOrEmpty(text)) {
            ToastUtils.showShort("文字不能为空");
            return;
        }

        if (text.length() >= 50) {
            ToastUtils.showShort("文字长度不能超过50个字符");
            return;
        }

        customWaitDialogUtils.show("命令下发中...");

        Airobots.getInstance().ledEditText(this.deviceSN, text, new CWMListener<MessageInfo<String>>() {
            @Override
            public void onSuccess(String message, MessageInfo<String> stringMessageInfo) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发成功");
            }

            @Override
            public void onError(int code, String message) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发失败");
            }
        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        customWaitDialogUtils.dismiss();
    }
}